package leetcode.search;

import leetcode.search.comon.VersionControl;

class Solution278 extends VersionControl {
    public int firstBadVersion(int n) {
        int left = 1;
        int right = n;
        while (left <= right) {
            if (left == right) {
                break;
            }
            int mid = left + (right - left) / 2;
            if (isBadVersion(mid)) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return right;
    }
}

public class leetcode278 {
    public static void main(String[] args) {
        Solution278 solution278 = new Solution278();
        test278(solution278, 5, 4);
        test278(solution278, 1, 1);
    }

    private static void test278(Solution278 solution278, int n, int badVersion) {
        solution278.setBadVersion(badVersion);
        System.out.println(solution278.firstBadVersion(n));
    }
}
